﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataStructureSample.Sorts
{
    public class QuickSort
    {
        public static void Sort(int[] arr, int left, int right)
        {
            if (left < right)
            {
                var temp = arr[left];
                var i = left;
                var j = right;
                while (i < j)
                {
                    while (i < j)
                    {
                        if (arr[i] > arr[j])
                        {
                            arr[i] = arr[j];
                            break;
                        }
                        else
                        {
                            j--;
                        }
                    }
                    while (i < j)
                    {
                        if (arr[i] < arr[j])
                        {
                            arr[j] = arr[i];
                            break;
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
                arr[i] = temp;
                Sort(arr, left, i - 1);
                Sort(arr, i + 1, right);
            }
        }
    }
}
